using System;
using System.Web.UI;
using ud_Utilities;

namespace ud_Controls
{
    public partial class CounterControls : UserControl
    {
        ControlsModuleConfiguration config = new ControlsModuleConfiguration();
        public ControlsModuleConfiguration Config
        {
            get { return config; }
            set { config = value; }
        }

        private string imageSiteRoot = string.Empty;
        public string ImageSiteRoot
        {
            get { return imageSiteRoot; }
            set { imageSiteRoot = value; }
        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            Load += Page_Load;
            EnableViewState = false;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            PopulateLabels();
            PopulateControls();
        }

        private void PopulateControls()
        {
            DBUtilities repository = new DBUtilities();
            if (Session["counter"] == null)
            {
                Session["counter"] = 1;
                repository.UpdateCounter();
            }
            lblVisitor.Text = repository.GetCounter(config.NumberDisplay, config.UseImage, ImageSiteRoot);
        }

        private void PopulateLabels()
        {
            lblHeader.Text = config.HeaderText;
            lblFooter.Text = config.FooterText;
        }
    }
}
